define([ "dojo/_base/declare", "gistech/widgets/baseWidget/BaseWidget",
         "gistech/widgets/ToolBox/ToolBox",
         "dojo/_base/lang",
         "dojo/on",
         "dojo/query",
         "dojo/dom-style",
         "dojo/dom-class",
         "dojo/keys",
         "dojo/topic",
         "dojo/text!./templates/Template.html"],
    function(declare,BaseWidget,ToolBox11,lang,on,query, domStyle,domClass,keys,topic,template) {
        return declare([BaseWidget], {
        	//模板页面
            templateString : template,
            _isExpand:undefined,
            expandState:"left",
            initExpand:true,
            left:null,
            right:null,
            top:null,
            bottom:null,
            _stateMap:{"left":"right","right":"left","top":"bottom","bottom":"top"},
            constructor : function(args) {
            	this.inherited(arguments);
                this.expandState=args.expandState;
                this.left=args.left;
                this.right=args.right;
                this.top=args.top;
                this.bottom=args.bottom;
                this.eventName=args.eventName;
                this.id=args.id;
                this.map=args.map;
                this.toolbox=null;
            },
            //组件初始化方法
            postCreate : function() {
            	this.inherited(arguments);
            	this.init();//设置该组件的位置
            	this.setExpand(this.initExpand);
            	this.addEvents();
            },
            /**初始化箭头组件的位置*/
            init:function(){
            	domStyle.set(this.domNode,"left",this.left);
            	domStyle.set(this.domNode,"right",this.right);
            	domStyle.set(this.domNode,"top",this.top);
            	domStyle.set(this.domNode,"bottom",this.bottom);
            },
            /**设置箭头的位置样式  默认箭头的图标样式是指向上的*/
            setExpand:function(expand){
//            	debugger
            	if(expand!==this._isExpand){
            		var negState=this._stateMap[this.expandState];//bottom
            		dojo.removeClass(this.domNode,this._isExpand?this.expandState:negState);//移除bottom类样式
            		dojo.addClass(this.domNode,expand?this.expandState:negState);//添加top类样式 
            		this._isExpand=expand;
            	}
            },
            /**绑定事件*/
            addEvents:function(){
            	topic.subscribe("ChangeArrowDirection", lang.hitch(this, this.ChangeArrowDirection));
            	on(this.domNode,"click",lang.hitch(this,this.clickHandle));
            },
            /**点击箭头图标的时候触发*/
            clickHandle:function(){
            	//debugger
            	this.setExpand(!this._isExpand);
            	if (this.eventName){
            		if(this.toolbox == null){
            			this.toolbox=new ToolBox11({map:this.map,container:dojo.body()});
            		}
            		this.toolbox.toggleToolBox(this._isExpand);
            	}
            	//debugger
            	$(this.toolbox.domNode).css('marginRight',parseInt($(this.domNode).css('marginRight')));
            },
            ChangeArrowDirection:function(args){
            	if (this.id==args.id){
            		this.setExpand(args.expand);
            	}
            },
            startup:function(){
            	this.inherited(arguments);
            },
            destroy:function(){
            	this.inherited(arguments);
            }
        });
    });
